﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QLKS.BUS;
using QLKS.DTO;

namespace QLKS.Presentation
{
    public partial class frmChiPhiVatTu_Lap : Form
    {
        public frmChiPhiVatTu_Lap()
        {
            InitializeComponent();
        }

        Phong_BUS objPhong = new Phong_BUS();
        VatTu_BUS objVT = new VatTu_BUS();
        ChiPhiVatTu_BUS objCP = new ChiPhiVatTu_BUS();

        public ChiPhiVatTu_DTO cp_DTO = new ChiPhiVatTu_DTO();

        private void frmChiPhiVatTu_Lap_Load(object sender, EventArgs e)
        {
            FormLoad();
        }

        private void FormLoad()
        {
            txtMaNV.Text = cp_DTO.MaNV.ToString();
            txtMaCP.Text = objCP.GetMaCPVT().ToString();

            //load cbxphong
            DataTable dtphong = objPhong.GetPhong();
            cbxPhong.DataSource = dtphong;
            cbxPhong.DisplayMember = "TenPhong";
            cbxPhong.ValueMember = "MaPhong";

            //load cbxvattu
            DataTable dtvattu = objVT.GetVatTu();
            cbxVatTu.DataSource = dtvattu;
            cbxVatTu.DisplayMember = "TenVatTu";
            cbxVatTu.ValueMember = "MaVatTu";

            btnLap.Enabled = true;
            btnMoi.Enabled = false;
        }

        private void btnLap_Click(object sender, EventArgs e)
        {
            if (txtChiPhi.Text != "")
            {
                cp_DTO.MaCP = int.Parse(txtMaCP.Text);
                cp_DTO.MaNV = int.Parse(txtMaNV.Text);
                cp_DTO.MaPhong = int.Parse(cbxPhong.SelectedValue.ToString());
                cp_DTO.MaVatTu = int.Parse(cbxVatTu.SelectedValue.ToString());
                cp_DTO.NgayLap = dtpNgayLap.Value;
                cp_DTO.ChiPhi = double.Parse(txtChiPhi.Text);

                if (objCP.INSERT_CPVT(cp_DTO))
                {
                    MessageBox.Show("Đã lập!");
                    btnMoi.Enabled = true;
                    btnLap.Enabled = false;
                }
            }
            else
                MessageBox.Show("Bạn phải nhập đủ thông tin!");
        }

        private void btnMoi_Click(object sender, EventArgs e)
        {
            FormLoad();
        }
    }
}